package com.wthink.hzgj.util

import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.net.Uri
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
/*import com.bumptech.glide.Glide
import jp.wasabeef.glide.transformations.RoundedCornersTransformation*/

class DatabindAdapters {

/*
    companion object {
        @JvmStatic
        @BindingAdapter(
            value = arrayOf(
                "imageUrl",
                "placeDrawableId",
                "errorDrawableId",
                "cornerType",
                "cornerRadius"
            ),
            requireAll = false
        )
        fun ImageView.setImgUrl(
            imageUrl: String,
            placeDrawableId: Int?,
            errorDrawableId: Int?,
            cornerType: RoundedCornersTransformation.CornerType?,
            cornerRadius: Int = 0
        ) {
            val builder = Glide.with(context)
                .load(imageUrl)

            cornerType?.let {
                builder.transform(
                    RoundedCornersTransformation(
                        cornerRadius,
                        0,
                        cornerType
                    )
                )
            }


            placeDrawableId?.let {
                builder.placeholder(placeDrawableId)
            }
            errorDrawableId?.let {
                builder.error(errorDrawableId)
            }

            builder.into(this)
        }

        @JvmStatic
        @BindingAdapter("android:src")
        fun setImageUri(view: ImageView, imageUri: String?) {
            if (imageUri == null) {
                view.setImageURI(null)
            } else {
                view.setImageURI(Uri.parse(imageUri))
            }
        }

        @JvmStatic
        @BindingAdapter("android:src")
        fun setImageUri(view: ImageView, imageUri: Uri) {
            view.setImageURI(imageUri)
        }

        @JvmStatic
        @BindingAdapter("android:src")
        fun setImageDrawable(view: ImageView, drawable: Drawable) {
            view.setImageDrawable(drawable)
        }

        @JvmStatic
        @BindingAdapter("android:src")
        fun setImageResource(imageView: ImageView, resource: Int) {
            imageView.setImageResource(resource)
        }

        @JvmStatic
        @BindingAdapter("android:typeface")
        fun setTypeface(v: TextView, style: String) {
            when (style) {
                "bold" -> v.setTypeface(null, Typeface.BOLD)
                else -> v.setTypeface(null, Typeface.NORMAL)
            }
        }

    }
*/
}